package com.nbf.Collections;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/** Represents a security<br>
 * Contains its symbol and accompanying data for each entry date
 * 
 * @author Zachary David
 *
 */
public class SecurityInfo
{
	private final String _symbol;
	private Map<Long, DataPack> _dates = new HashMap<Long, DataPack>();
	
	public SecurityInfo(String symbol)
	{
		_symbol = symbol;
	}
	
	/**Only adds if a MarketVariable of the same name does not already exist.
	 *  This is to prevent variable collisions between files.
	 * @param date date in yyyyMMdd format
	 * @param name name of MarketVariable
	 * @param value value of MarketVariable
	 * @return if it was successfully added
	 */
	public boolean tryAdd(Long date, String name, Double value)
	{
		DataPack dp = _dates.get(date);
		if(dp == null)
		{
			dp = new DataPack();
		}
		return dp.tryAdd(name, value);
	}
	
	public Double tryGet(Long date, String name)
	{
		DataPack dp = _dates.get(date);
		if(dp == null)
			return null;
		return dp.tryGet(name);
	}
	
	public boolean containsDate(Long date)
	{
		if(_dates.get(date) == null)
			return false;
		return true;
	}
	
	/** To determine if this security contains all of the dates in a calibration period
	 * 
	 * @param dates
	 * @return true if there is a DataPack for each date
	 */
	public boolean containsAllDates(List<Long> dates)
	{
		for(Long date : dates)
		{
			if(!containsDate(date))
				return false;
		}
		return true;
	}
	
	public int hashCode()
	{
		return _symbol.hashCode();
	}
	
	public boolean equals(Object obj)
	{
		if(obj == null)
			return false;
		
		if(this == obj)
			return true;
		
		if(obj instanceof String)
			return _symbol.equals((String)obj);
		
		return false;
	}
}
